import urllib.request
from lxml import etree

url = 'http://www.baidu.com'
headers = {
        'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36'
}
# 请求对象定制
request = urllib.request.Request(url=url,headers=headers)
#模拟游览器访问服务器
response = urllib.request.urlopen(request)
#获取网页源代码
content = response.read().decode('utf8')
# print(content)
#解析网页源代码获取我们想要的数据
tree = etree.HTML(content)
result = tree.xpath('//input[@id="su"]/@value')[0]
print(result)